local xiejin_viewas = fk.CreateSkill{
  name = "hanqing__xiejin&",
}

Fk:loadTranslationTable{
  ["hanqing__xiejin&"] = "胁进",
  [":hanqing__xiejin&"] = "经李兑允许，你可以视为使用一张【过河拆桥】，若目标不为李兑，须先弃置一张牌。",
}

xiejin_viewas:addEffect("viewas", {
  mute = true,
  pattern = "dismantlement",
  prompt = "#hanqing__xiejin-yin",
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and not player:prohibitDiscard(to_select)
  end,
  view_as = function(self, player, cards)
    if #cards > 1 then return end
    local card = Fk:cloneCard("dismantlement")
    card.skillName = "hanqing__xiejin"
    if #cards == 1 then
      table.insert(card.skillNames, "hanqing__xiejin_other")
      card:addFakeSubcards(cards)
    end
    return card
  end,
  before_use = function (self, player, use)
    local room = player.room
    local to = table.find(room:getOtherPlayers(player, false), function (p)
      return p:hasSkill("hanqing__xiejin") and p:getSwitchSkillState("hanqing__xiejin", false) == fk.SwitchYin
    end)
    if to == nil then return self.name end
    player:broadcastSkillInvoke("hanqing__xiejin", 2)
    room:notifySkillInvoked(player, "hanqing__xiejin", "control")
    room:playCardEmotionAndSound(player, use.card)
    if #use.tos > 0 and not use.noIndicate then
      room:doIndicate(player, use.tos)
    end
    if #use.card.fake_subcards > 0 then
      room:throwCard(use.card.fake_subcards, "hanqing__xiejin", player, player)
    end
    if not to.dead then
      if room:askToSkillInvoke(to, {
        skill_name = "hanqing__xiejin",
        prompt = "#hanqing__xiejin-ask::"..player.id,
      }) then
        room:setPlayerMark(to, MarkEnum.SwithSkillPreName.."hanqing__xiejin", to:getSwitchSkillState("hanqing__xiejin", true))
      else
        room:setPlayerMark(player, "hanqing__xiejin_failed-phase", 1)
        return self.name
      end
    end
  end,
  enabled_at_play = function (self, player)
    return table.find(Fk:currentRoom().alive_players, function (p)
      return p:hasSkill("hanqing__xiejin") and p:getSwitchSkillState("hanqing__xiejin", false) == fk.SwitchYin
    end) and player:getMark("hanqing__xiejin_failed-phase") == 0
  end,
  enabled_at_response = function (self, player, response)
    return not response and table.find(Fk:currentRoom().alive_players, function (p)
      return p:hasSkill("hanqing__xiejin") and p:getSwitchSkillState("hanqing__xiejin", false) == fk.SwitchYin
    end) and player:getMark("hanqing__xiejin_failed-phase") == 0
  end,
})

xiejin_viewas:addAI(nil, "vs_skill")

return xiejin_viewas
